<?php
/**
 * Created by PhpStorm.
 * User: yuanluke
 * Date: 4/30/16
 * Time: 11:54
 */

namespace App\Http\Utils\Common;

use Log;

class MathUtils
{

    /**
     * 取值区间
     * @param array $params 要取值的数组
     * @param $val  设置每个区间的刻度是多大
     * @return array
     */
    public static function interval(array $params, $val = 500)
    {
        $min = floor(min($params) / $val) * $val;
        $max = ceil(max($params) / $val) * $val;
        $result = [];
        for ($i = $min; $i <= $max; $i = $i + $val) {
            $arr = [];
            if ($i < $max) {
                $arr['start'] = $i;
                $arr['end'] = $i + $val;
            } else {
                $arr['start'] = 0;
                $arr['end'] = $i;
            }
            $result[] = $arr;
        }
        return $result;
    }


}